
// https://leetcode.cn/problems/kth-largest-element-in-a-stream/description/

class KthLargest
{
public:
    KthLargest(int k, vector<int>& nums)
    {
        _k = k;
        for (size_t i = 0; i < nums.size(); ++i)
        {
            _pq.push(nums[i]);
            if (_pq.size() > k)
                _pq.pop();
        }
    }

    int add(int val)
    {
        _pq.push(val);
        if (_pq.size() > _k)
            _pq.pop();
        return _pq.top();
    }

private:
    priority_queue<int, vector<int>, greater<int>> _pq;
    int _k;
};